package org.jaaksi.kottlindemo.function

class Test {
  // 可变长参数用 vararg声明
  fun foo(vararg strings: String) { /*……*/
  }

  fun test() {
    foo(strings = *arrayOf("a", "b", "c"))
    fun0 {
      5 > 3
    }

    test1(1, 2) { a, b ->
      a * b
    }

  }

  fun fun0(isTure: () -> Boolean): Boolean {
    return isTure.invoke()
  }

  inline fun <T> List<T>.getOrElse(index: Int, defaultValue: (Int) -> T): T {
    return if (index in 0..lastIndex) get(index) else defaultValue(index)
  }

  inline fun test1(a: Int, b: Int, operation: (Int, Int) -> Int): Int {
    return operation(a, b)
  }
}